var gulp = require("gulp");
var postcss = require("gulp-postcss");
var autoprefixer = require("autoprefixer");
var pxtoviewport = require('postcss-px-to-viewport');
var less = require('gulp-less');

gulp.task('styles',function(){
  
  var processors = pxtoviewport({
    viewportWidth: 750,
    viewportHeight: 1336,
    viewportUnit: 'vw'
  });

  return gulp.src('less/*less')
    .pipe(less())
    .pipe(postcss([autoprefixer,processors]))
    .pipe(gulp.dest('css'));
});

gulp.task('default',['styles']);

//监听文件变化，自动编译
var watcher = gulp.watch('less/*.less',['default']);

watcher.on('change',function(ev){
  console.log("File:"+ev.path+" was "+ev.type+" ,running tasks...");
});